local zenhui = fk.CreateSkill {
  name = "tyj_heg__zenhui",
}
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"

Fk:loadTranslationTable {
  ["tyj_heg__zenhui"] = "谮毁",
  [":tyj_heg__zenhui"] = "与你势力相同且装备区内牌数为全场最多的角色使用【杀】或普通锦囊牌时，你可以令一名角色成为此牌的额外目标，然后其弃置此牌使用者的一张牌。",
  ["#tyj__zenhui_target"] = "是否发动 谮毁 为 %arg 指定一个额外的目标？",
  ["$tyj_heg__zenhui1"] = "你可别不识抬举！",
  ["$tyj_heg__zenhui2"] = "你也休想置身事外！",
}

zenhui:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zenhui.name) and H.compareKingdomWith(player, target) and
        (data.card:isCommonTrick() or data.card.trueName == 'slash') and data.card.trueName ~= 'threaten_emperor' and
        table.every(player.room:getOtherPlayers(target),
          function(p) return #target:getCardIds('e') >= #p:getCardIds('e') end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = data:getExtraTargets(),
      skill_name = zenhui.name,
      prompt = "#tyj__zenhui_target:::" .. data.card:toLogString(),
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, { tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    data:addTarget(to)
    if to:isAlive() and #target:getCardIds('he') > 0 then
      local card = room:askToChooseCard(to, {
        target = target,
        flag = "he",
        skill_name = zenhui.name,
        prompt = "谮毁：弃置其一张牌",
      })
      room:throwCard(card, zenhui.name, target, to)
    end
  end,
})
return zenhui
